package com.zjgsu.controller;/*
Date: 2018-04-10 21:42
Description: 
*/

import com.zjgsu.entity.User;
import com.zjgsu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/tlogin")
public class Login {
    @Autowired
    UserService userService;
    @ResponseBody
    @RequestMapping(value = "/user/{method}",method = RequestMethod.POST,params = {"username","password"})
    public User loginByUser(@PathVariable String method,String username,String password, HttpServletRequest request){
        User user = userService.checkUser(username, password);
        if (user != null){
            request.getSession().setAttribute("user",user);
            return user;
        }
        return null;
    }
}
